package cn.wzy.controller;

import cn.wzy.annotation.AnPermission;
import cn.wzy.pojo.Permission;
import cn.wzy.results.ResponseResult;
import cn.wzy.service.PermissionService;
import cn.wzy.vo.GoPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Permission)表控制层
 *
 * @author makejava
 * @since 2022-12-12 19:57:23
 */
@RestController
@RequestMapping("/permission")
@AnPermission(name = "权限管理",descs = "权限资源管理")
@Api(value = "权限")
public class PermissionController {
    /**
     * 服务对象
     */
    @Resource
    private PermissionService permissionService;

    /*
    * 权限分页
    * */
    @PostMapping("/page")
    @AnPermission(name = "权限资源分页高级查询")
    @ApiOperation(value = "权限资源分页")
    public ResponseResult permissionPage(@RequestBody GoPageVo goPageVo){
        return permissionService.permissionPage(goPageVo);
    }

    /*
    * 权限修改/添加
    * */
    @PostMapping
    @AnPermission(name = "权限的修改或者添加")
    @ApiOperation(value = "权限的修改/添加")
    public ResponseResult savePermission(@RequestBody Permission permission){
        return permissionService.savePermission(permission);
    }

    /*
    * 删除单个
    * */
    @DeleteMapping("/{id}")
    @AnPermission(name = "对某个资源的删除")
    @ApiOperation(value = "删除单个资源")
    public ResponseResult deletePermission(@PathVariable("id") Long id){
        return permissionService.deletePermission(id);
    }

    /*
    * 批量删除
    * */
    @PatchMapping
    @AnPermission(name = "对资源批量的删除")
    @ApiOperation(value = "批量删除")
    public ResponseResult deletePermissionList(@RequestBody List<Long> ids){
        return permissionService.deletePermissionList(ids);
    }

    /*
    * 获取一级权限
    * */
    @GetMapping("/Level")
    @AnPermission(name = "查询一级权限")
    @ApiOperation(value = "获取一级权限")
    public ResponseResult getPermissionParent(){
        return permissionService.getPermissionParent();
    }

    /*
    *  获取到权限数
    * */
    @GetMapping("/tree")
    @ApiOperation(value = "获取权限数")
    @AnPermission(name = "获取到权限数")
    public ResponseResult getPermissionTree(){
        return permissionService.getPermissionTree();
    }

    /*
    * 获取到所有权限
    * */
    @GetMapping("/allSn")
    @ApiOperation(value = "获取所有权限sn")
    @AnPermission(name = "获取所有权限sn")
    public ResponseResult getPermissionAllSn(){
        return permissionService.getAllSn();
    }
}

